﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AppService.Dao;
using AppService.Model;
using Newtonsoft.Json;
using WaitInHope.Models;

namespace WaitInHope.Controllers
{
    public class HomeController : Controller
    {
        private static readonly DoubleColorBallDao dao = new DoubleColorBallDao();
        private readonly List<DoubleColorBall> _list=new List<DoubleColorBall>();


        public HomeController()
        {
            _list = dao.GetList().OrderByDescending(x => x.Issue).ToList();
        }

        public ActionResult Index()
        {



            ViewData["Top10List"] = _list.Take(20).ToList();
            return View();
        }

        [HttpPost]
        public string Search(SearchModel model)
        {
            var list = new List<DoubleColorBall>(_list);
            if (!string.IsNullOrEmpty(model.Year))
            {
                list = list.Where(x => x.Year == model.Year).ToList();
            }

            if (!string.IsNullOrEmpty(model.Date))
            {
                list = list.Where(x => x.OpenDate.ToString("MM-dd") == model.Date).ToList();
            }

            if (!string.IsNullOrEmpty(model.Week))
            {
                list = list.Where(x => x.Week == model.Week).ToList();
            }

            if (!string.IsNullOrEmpty(model.Issue))
            {
                list = list.Where(x => x.Issue== model.Issue).ToList();
            }

            return JsonConvert.SerializeObject(list);
        }




    }
}